package day1117_3;

import java.io.*;
class   ZhuZhuXia  implements Serializable {
    String name;
    transient String skill;//序列化时，不保存skill
}
public class B1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos=new ObjectOutputStream(
                new FileOutputStream("D:\\obj.txt")
        );//1.输出流(obj.txt)

        ZhuZhuXia  zzx=new ZhuZhuXia();
        zzx.name="猪猪侠";  zzx.skill="棒棒糖武器";//猪猪侠对象
        oos.writeObject(zzx);//write(猪猪侠对象)
        oos.close();//输出流.close();


        //对象输入流读取obj.txt.  只能读到name
        ObjectInputStream ois=new ObjectInputStream(
                new FileInputStream("D:\\obj.txt")
        );//1.对象输入流
        ZhuZhuXia  zx=(ZhuZhuXia) ois.readObject();//2.readObject()
        System.out.println(zx.name);
        System.out.println(zx.skill);

        ois.close();//3.close





    }
}
